<?php
use app\models\Mall;
use yii\helpers\Url;

$web = Url::base();
$institution_code = Mall::getCurrentInstitutionCode();

$this->title = '卡卷详情';
?>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall/card-goods-detail.css" />


<!---------------------------------------------------->
<div class="goods">
    <div class="right-extra">
        <div>
            <div id="preview" class="spec-preview">
                <span class="jqzoom"><img src="<?= $goods['info']->picBg ?>"/></span>
            </div>
        </div>

    </div>

    <div class="goods-referral fl">
        <p class="title"><?= $goods['info']->title ?></p>
        <p class="price">¥:<?= $goods['info']->price ?></p>
        <div class="card-massage">
            <div>
                <span class="name">剩余库存</span>
                <span class="txt" style="color: #E1515B;"><?= $goods['amount'] ?></span>
            </div>
            <div>
                <span class="name">适用地区</span>
                <span class="txt"><?= $goods['districtStr'] ?></span>
            </div>
            <div>
                <span class="name">使用有效期</span>
                <span class="txt-1"><?= date('Y-m-d', $goods['info']->dateValidFrom) ?> 至 <?= date('Y-m-d', $goods['info']->dateValidTo) ?></span>
            </div>
            <div>
                <span class="name">供应商</span>
                <span class="txt-2"><?= $goods['info']->brands ?></span></span>
            </div>
        </div>
        <a  class="btn">免费领取</a>
    </div>
</div>
<div class="card-code-window" style="display: none;">
    <div class="content">
        <a class="close-btn"><img  src="<?= $web ?>/images/mall/close-btn-nouveau.png"/></a>
        <img class="code" src="<?=Url::to(['mall-m/qr-code-out','text'=>"http://m.fanso2o.com/shop/".$goods['shopId'],'margin'=>1])?>" />
        <p>使用微信扫描二维码，领取卡券</p>
    </div>
    <div class="shade"></div>
</div>
<script type="text/javascript">
    $(function(){
        $(".goods-referral .btn").click(function(){
            $(".card-code-window").show();
        });
        $(".card-code-window .content .close-btn,.shade").click(function(){
            $(".card-code-window").hide();
        })
    });
</script>

<div class="history-and-details">
    <div class="goods-history">
        <p class="history-name">您浏览过的历史商品</p>
        <div class="goods-history-list">
            <ul>

            </ul>
        </div>
    </div>
    <div class="goods-details">
        <p class="title-name">使用须知</p>
        <div class="notice">
            <?= $goods['info']->description ?>
        </div>
    </div>
</div>
<!-------------------->

<script>
    $(function ($) {

//        myStorage.clear();
        //展示历史足迹
        if (myStorage) {
            //判断是否同一机构
            var institutionCode = '<?=$institution_code?>';
            if (myStorage.institution_code) {
                if (myStorage.institution_code != institutionCode) {
                    myStorage.clear();
                }

            } else {
                myStorage.institution_code = institutionCode;
            }

            if (myStorage.his_goods_array) {
                var his_goods_array = JSON.parse(myStorage.his_goods_array);
                var data = {};
                data.goods_code_list = his_goods_array;
                requestJsonMallM('get-his-goods-handler', data, true, function (response) {
                    if (response.status == 0) {
                        var goods_list = response.data;
                        var html = '';
                        for (var j = 0; j < his_goods_array.length; j++) {
                            for (var i = 0; i < goods_list.length; i++) {
                                if (his_goods_array[his_goods_array.length - 1 - j] == goods_list[i].code) {
                                    html += '<li><a  href="goods-detail?goods_code=' + goods_list[i].code + '&institution_code=<?=$institution_code?>">';
                                    html += '<img src="' + goods_list[i].image_url + '@300w"/></a>';
                                    var crossborder_span = '';
                                    if (goods_list[i].is_crossborder == 1) {
                                        crossborder_span = '<span class="cross-title-icon">跨境</span>';
                                    }
                                    html += '<div class="goods-history-text"><p class="goods-history-title">' + crossborder_span + goods_list[i].name + '</p>';
                                    html += '<p class="goods-history-integral">' + goods_list[i].integral_unit + ':' + parseInt(goods_list[i].selling_integral) + '</p></div>';
                                    html += '</li>';
                                    break;
                                }
                            }
                        }
                        $(".goods-history-list ul").append(html);
                    }
                });
            }
        }

        //添加当前商品访问记录,显示10个
        if (myStorage) {
            var goods_code = false;
            if (goods_code) {
                var his_goods_array = [];
                var new_goods_array = [];
                if (myStorage.his_goods_array != undefined) {
                    his_goods_array = JSON.parse(myStorage.his_goods_array);
                }

                if (his_goods_array.length > 0) {
                    //只显示9个
                    var temp_array = [];
                    var j = 0;
                    for (var i = 0; i < his_goods_array.length; i++) {
                        if (his_goods_array[his_goods_array.length - 1 - i] != goods_code) {
                            temp_array.push(his_goods_array[his_goods_array.length - 1 - i]);
                            j = j + 1;
                            if (j == 8) {
                                break;
                            }
                        }
                    }

                    for (var i = 0; i < temp_array.length; i++) {
                        new_goods_array.push(temp_array[temp_array.length - 1 - i]);
                    }
                }

                new_goods_array.push(goods_code);
                myStorage.his_goods_array = JSON.stringify(new_goods_array);
            }
        }


    });
    //删除历史足迹
    function delHisNoStockGoods(goods_code) {
        var his_goods_array = [];
        if (myStorage.his_goods_array != undefined) {
            his_goods_array = JSON.parse(myStorage.his_goods_array);
            his_goods_array.remove(goods_code);
        }
    }
</script>